package com.appsindy.reserv.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.log4j.Logger;

import com.appsindy.common.AppsindyConstants;
import com.appsindy.common.bo.GlobalUser;
import com.appsindy.common.util.DateUtils;
import com.appsindy.common.util.NumberUtil;
import com.appsindy.common.util.StringUtils;
import com.appsindy.common.vo.UserVO;
import com.appsindy.reserv.ReservConstants;
import com.appsindy.reserv.bo.Combo;
import com.appsindy.reserv.bo.Customer;
import com.appsindy.reserv.bo.GenFreeRoom2TrackMap;
import com.appsindy.reserv.bo.Info4RoomMap;
import com.appsindy.reserv.bo.Payment2Shift;
import com.appsindy.reserv.bo.ReserveDetail;
import com.appsindy.reserv.bo.ReserveHeaderMap;
import com.appsindy.reserv.bo.ReserveInfo;
import com.appsindy.reserv.bo.ReserveInfoMap;
import com.appsindy.reserv.bo.ReserveItem;
import com.appsindy.reserv.bo.ReservePayment;
import com.appsindy.reserv.bo.ReservePaymentDetail;
import com.appsindy.reserv.bo.ReserveRoom;
import com.appsindy.reserv.bo.ReserveTypeOfRoom;
import com.appsindy.reserv.bo.RoomRateMap;
import com.appsindy.reserv.bo.ServiceHeader;
import com.appsindy.reserv.bo.ServiceResultMap;
import com.appsindy.reserv.dao.ReserveOverviewDAO;
import com.appsindy.reserv.dao.mapper.CustomerMapper;
import com.appsindy.reserv.service.BaseServices;
import com.appsindy.reserv.service.ReservationServices;
import com.appsindy.reserv.vo.CalendarInfo;
import com.appsindy.reserv.vo.CalendarMatrix;
import com.appsindy.reserv.vo.CustomerVO;
import com.appsindy.reserv.vo.DiscountVO;
import com.appsindy.reserv.vo.GroupInfoVO;
import com.appsindy.reserv.vo.Info;
import com.appsindy.reserv.vo.ItemVO;
import com.appsindy.reserv.vo.ReserveDetailVO;
import com.appsindy.reserv.vo.ReserveInfoRoomVO;
import com.appsindy.reserv.vo.ReserveInfoTypeVO;
import com.appsindy.reserv.vo.ReserveInfoVO;
import com.appsindy.reserv.vo.ReservePaymentDetailVO;
import com.appsindy.reserv.vo.ReservePaymentVO;
import com.appsindy.reserv.vo.ReservePrintReceiptVO;
import com.appsindy.reserv.vo.RoomVO;
import com.appsindy.reserv.vo.TypeOfRoomVO;

public class ReservationServicesImpl extends BaseServices implements ReservationServices {
	
	protected final Logger log = Logger.getLogger(getClass());
	
	private static final String S_ORG_ID				= "S_ORG_ID";
	
	private static final String USERLOGIN_DEFAULT		= "1";
	private static final String ORG_ID_DEFAULT			= "1";
	private static final Integer SHIFT_TRANS_ID_DEFAULT	= 0;
	
	private CustomerMapper customerMapper;
	private ReserveOverviewDAO reserveOverviewDAO;
	
	public Customer getCustomer(int id) {
		log.info("[ReservationServices.getCustomer] Id = " + id);
		return getCustomerMapper().selectCustomerById(id);
	}
	
	public List<Customer> getAllCustomers(){
		return getCustomerMapper().selectAllCustomer();
	}
	
	public CustomerMapper getCustomerMapper() {
		return customerMapper;
	}
	public void setCustomerMapper(CustomerMapper customerMapper) {
		this.customerMapper = customerMapper;
	}

	public void setReserveOverviewDAO(ReserveOverviewDAO reserveOverviewDAO) {
		this.reserveOverviewDAO = reserveOverviewDAO;
	}

	public ReserveOverviewDAO getReserveOverviewDAO() {
		return reserveOverviewDAO;
	}
	
	@Override
	public List<Combo> getMonthCombos(){
		log.info("Start ReservationServices.getMonthCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeName", ReservConstants.GlobalTypeMonth);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}

	@Override
	public List<Combo> getYearCombos(){
		log.info("Start ReservationServices.getYearCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeName", ReservConstants.GlobalTypeYear);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}

	@Override
	public List<Combo> getGroupCombos(){
		log.info("Start ReservationServices.getGroupCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().getGroupCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}

	@Override
	public List<Combo> getCustomerCombos(){
		log.info("Start ReservationServices.getCustomerCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().getCustomerCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
			e.printStackTrace();
		}
		return resultList;
	}

	@Override
	public List<Combo> getCustomerByHeaderCombos(int serviceHeaderId){
		log.info("Start ReservationServices.getCustomerByHeaderCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			if(serviceHeaderId > 0){
				Map<String, Object> paramM = new HashMap<String, Object>();   
				paramM.put("serviceHeaderId", serviceHeaderId);  
				resultList = getReserveOverviewDAO().getCustomerByHeaderCombos(paramM);
			}
		}catch(Exception e){
			log.error(e.getMessage());
			e.printStackTrace();
		}
		return resultList;
	}
	
	@Override
	public List<Combo> getStatusCombos(){
		log.info("Start ReservationServices.getStatusCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeName", ReservConstants.GlobalTypeServiceStatus);   
			paramM.put("orgId", orgId);  
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().getStatusCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}

	@Override
	public List<Combo> getGroupPopupCombos(){
		log.info("Start ReservationServices.getGroupPopupCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  			
			resultList = getReserveOverviewDAO().getGroupPopupCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}
	
	@Override
	public List<Combo> getTypeOfRoomCombos(){
		log.info("Start ReservationServices.getTypeOfRoomCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeName", ReservConstants.GlobalTypeTypeOfRoom);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}

	@Override
	public List<Combo> getRoomCombos(){
		log.info("Start ReservationServices.getRoomCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().getRoomCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}
	
	@Override
	public CalendarMatrix getCurrentReserve(int month, int year) {
		log.info("Start ReservationServices.getCurrentReserve...");
		CalendarMatrix matrix = new CalendarMatrix();
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			
			month = month-1;
			//set start day of month
			Calendar cStart = Calendar.getInstance(Locale.US);
			cStart.set(Calendar.MONTH, month);
			cStart.set(Calendar.YEAR, year);
			cStart.set(Calendar.DATE, 1);		
			Date startDate = cStart.getTime();		
			
			//set end of month
			Calendar cEnd = Calendar.getInstance(Locale.US);
			cEnd.set(Calendar.MONTH, month);
			cEnd.set(Calendar.YEAR, year);
			cEnd.set(Calendar.DATE, cEnd.getActualMaximum(Calendar.DAY_OF_MONTH));
			Date endDate = cEnd.getTime();
			
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("userId", userId);
			paramM.put("orgId", orgId);  
			paramM.put("dateFrom", startDate);
			paramM.put("dateTo", endDate);
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);
			paramM.put("paymentStatus", ReservConstants.ServiceStatusPayment);
			getReserveOverviewDAO().generateCalendar(paramM);
			List<CalendarInfo> resultList = getReserveOverviewDAO().selectCalendar(paramM);
			
			if(resultList != null && resultList.size() > 0){
				Calendar c = Calendar.getInstance(Locale.US);
				int day 	= 1;
				int week 	= 1;
				for(CalendarInfo info : resultList){ 
					c.setTime(info.getGenDate());
					info.setDay(""+c.get(Calendar.DATE));
					
					week 	= c.get(Calendar.WEEK_OF_MONTH);
					day		= c.get(Calendar.DAY_OF_WEEK);
					
					if(week==1&&day==1)			matrix.setSunW1(info);
					else if(week==2&&day==1)	matrix.setSunW2(info);
					else if(week==3&&day==1)	matrix.setSunW3(info);
					else if(week==4&&day==1)	matrix.setSunW4(info);
					else if(week==5&&day==1)	matrix.setSunW5(info);
					else if(week==6&&day==1)	matrix.setSunW6(info);
					else if(week==1&&day==2)	matrix.setMonW1(info);
					else if(week==2&&day==2)	matrix.setMonW2(info);
					else if(week==3&&day==2)	matrix.setMonW3(info);
					else if(week==4&&day==2)	matrix.setMonW4(info);
					else if(week==5&&day==2)	matrix.setMonW5(info);
					else if(week==6&&day==2)	matrix.setMonW6(info);
					else if(week==1&&day==3)	matrix.setTueW1(info);
					else if(week==2&&day==3)	matrix.setTueW2(info);
					else if(week==3&&day==3)	matrix.setTueW3(info);
					else if(week==4&&day==3)	matrix.setTueW4(info);
					else if(week==5&&day==3)	matrix.setTueW5(info);
					else if(week==6&&day==3)	matrix.setTueW6(info);
					else if(week==1&&day==4)	matrix.setWedW1(info);
					else if(week==2&&day==4)	matrix.setWedW2(info);
					else if(week==3&&day==4)	matrix.setWedW3(info);
					else if(week==4&&day==4)	matrix.setWedW4(info);
					else if(week==5&&day==4)	matrix.setWedW5(info);
					else if(week==6&&day==4)	matrix.setWedW6(info);
					else if(week==1&&day==5)	matrix.setThuW1(info);
					else if(week==2&&day==5)	matrix.setThuW2(info);
					else if(week==3&&day==5)	matrix.setThuW3(info);
					else if(week==4&&day==5)	matrix.setThuW4(info);
					else if(week==5&&day==5)	matrix.setThuW5(info);
					else if(week==6&&day==5)	matrix.setThuW6(info);
					else if(week==1&&day==6)	matrix.setFriW1(info);
					else if(week==2&&day==6)	matrix.setFriW2(info);
					else if(week==3&&day==6)	matrix.setFriW3(info);
					else if(week==4&&day==6)	matrix.setFriW4(info);
					else if(week==5&&day==6)	matrix.setFriW5(info);
					else if(week==6&&day==6)	matrix.setFriW6(info);
					else if(week==1&&day==7)	matrix.setSatW1(info);
					else if(week==2&&day==7)	matrix.setSatW2(info);
					else if(week==3&&day==7)	matrix.setSatW3(info);
					else if(week==4&&day==7)	matrix.setSatW4(info);
					else if(week==5&&day==7)	matrix.setSatW5(info);
					else if(week==6&&day==7)	matrix.setSatW6(info);
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return matrix;
	}
	
	@Override
	public List<Info> selectGroup(int group, String status){
		log.info("Start ReservationServices.selectGroup...");
		List<Info> resultList = new ArrayList<Info>();
		try{
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("groupId", group);
			paramM.put("status", status);
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().selectGroup(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}

	@Override
	public List<Info> selectCustomer(int customer, String status){
		log.info("Start ReservationServices.selectCustomer...");
		List<Info> resultList = new ArrayList<Info>();
		try{
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("customerId", customer);
			paramM.put("status", status);
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().selectCustomer(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}

	@Override
	public List<Info> selectRoom(int room, String status){
		log.info("Start ReservationServices.selectRoom...");
		List<Info> resultList = new ArrayList<Info>();
		try{
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("roomId", room);
			paramM.put("status", status);
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().selectRoom(paramM);
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return resultList;
	}

	@Override
	public ReserveInfoTypeVO selectAvailableTypeOfRoom(ReserveInfoTypeVO infoType){
		log.info("Start ReservationServices.selectAvailableTypeOfRoom...");
		List<TypeOfRoomVO> resultList = new ArrayList<TypeOfRoomVO>();
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("userId", userId);
			paramM.put("orgId", orgId);  
			paramM.put("dateFrom", infoType.getDateFrom());
			paramM.put("dateTo", infoType.getDateTo());
			paramM.put("typeOfRoom", infoType.getTypeOfRoom());
			paramM.put("groupId", infoType.getGroupInfoVO().getGroupId());
			paramM.put("groupIdCustomer", ReservConstants.GroupId4Customer);
			paramM.put("daysType", ReservConstants.GlobalTypeDaysType);
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);
			paramM.put("paymentStatus", ReservConstants.ServiceStatusPayment);
			getReserveOverviewDAO().generateReserveTypeOfRoom(paramM);
			List<ReserveTypeOfRoom> typeOfRoomList 	= getReserveOverviewDAO().selectGroupTypeOfRoom(paramM);
			List<ReserveTypeOfRoom> dateList 		= getReserveOverviewDAO().selectGroupDate(paramM);
			List<ReserveTypeOfRoom> reserveList 	= getReserveOverviewDAO().selectReserveTypeOfRoom(paramM);
			GroupInfoVO groupInfo 					= getReserveOverviewDAO().selectGroupInfo(paramM);

			if(groupInfo != null){
				infoType.setGroupInfoVO(groupInfo);
			}
			//v1.0
			TypeOfRoomVO typeOfRoomVO 	= null;
			List<RoomVO> roomList 		= null;
			RoomVO roomVO 				= null;
			int _id 					= 0;
			String _type 				= "";
			Date _date 					= null;			
			for(ReserveTypeOfRoom type : typeOfRoomList){
				typeOfRoomVO = new TypeOfRoomVO();
				_id 		= type.getTypeOfRoomId();
				_type 		= type.getTypeOfRoom();
				typeOfRoomVO.setId(_id);
				typeOfRoomVO.setType(_type);
				roomList 	= new ArrayList<RoomVO>();
				for(ReserveTypeOfRoom date : dateList){
					roomVO 	= new RoomVO();
					_date 	= date.getGenDate();
					roomVO.setDateGen(DateUtils.getDateStr(_date, false));
					for(ReserveTypeOfRoom bo : reserveList){
						if(_type.equalsIgnoreCase(bo.getTypeOfRoom()) && _date.compareTo(bo.getGenDate()) == 0){
							roomVO.setCntRoom(NumberUtil.toNumberStr(bo.getCntAvailableRoom(), 0));
							roomVO.setPrice(NumberUtil.getNumberStr(bo.getRateOfRoom(), 2));
							break;
						}
					}
					roomList.add(roomVO);
				}
				typeOfRoomVO.setRoomList(roomList);
				
				resultList.add(typeOfRoomVO);
			}
			
			infoType.setResultList(resultList);
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return infoType;
	}
	
	@Override
	public List<Combo> getZoneCombos(int typeOfRoom){
		log.info("Start ReservationServices.getZoneCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeOfRoom", typeOfRoom);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getZoneCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}	
	@Override
	public List<Combo> getFloorCombos(int typeOfRoom, String zone){
		log.info("Start ReservationServices.getFloorCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeOfRoom", typeOfRoom);   
			paramM.put("zone", zone);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getFloorCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}	
	
	@Override
	public ReserveInfoTypeVO processReserve(ReserveInfoTypeVO infoType, String serviceStatus){
		log.info("Start ReservationServices.processReserve...");
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			ReserveInfoMap seqM = new ReserveInfoMap();
			seqM.setUserId(Integer.parseInt(userId));
			seqM.setOrgId(Integer.parseInt(orgId));  			
			seqM.setGroupId(infoType.getGroupInfoVO().getGroupId());  			
			getReserveOverviewDAO().getSeqHeader(seqM);
			
			int seqId = 0;
			int serviceHeaderId = 0;
			if(seqM != null){
				seqId = seqM.getSeqId();
				List<ReserveInfoVO> reserveInfoList = infoType.getReserveList(); 
				int index 	= 0;
				ReserveInfo bo = null;
				GenFreeRoom2TrackMap infoM = null;
				Date nowDate = new Date();
				//clear temp
				getReserveOverviewDAO().clearReserveDetailTemp(seqM);
				boolean isSuccess = true;
				for(ReserveInfoVO vo : reserveInfoList){
					bo = new ReserveInfo();
					bo.setSeqId(seqId);
					bo.setOrgId(seqM.getOrgId());
					bo.setLineNum(++index);
					bo.setDateFrom(DateUtils.createDate(vo.getDateFrom(), false));
					bo.setDateTo(DateUtils.createDate(vo.getDateTo(), false));
					bo.setTypeOfRoomId(StringUtils.toInt(vo.getTypeOfRoomId()));
					bo.setTypeOfRoom(vo.getTypeOfRoom());
					bo.setZone(vo.getZone());
					bo.setFloor(vo.getFloor());
					bo.setDay(StringUtils.toInt(vo.getDay()));
					bo.setQtyRoomPerDay(StringUtils.toInt(vo.getQtyRoomPerDay()));
					bo.setRatePerRoom(StringUtils.toDouble(vo.getRatePerRoom()));
					bo.setTotalAmount(StringUtils.toDouble(vo.getTotalAmount()));
					bo.setBreakfast("1".equalsIgnoreCase(vo.getBreakfast())?1:0);
					bo.setCreateBy(seqM.getUserId());
					
					getReserveOverviewDAO().insertReserveDetailTemp(bo);
					
					infoM = new GenFreeRoom2TrackMap();
					infoM.setUserId(bo.getCreateBy());
					infoM.setOrgId(bo.getOrgId());
					infoM.setServiceDate(nowDate);
					infoM.setServiceStatus(serviceStatus);
					infoM.setSeqId(seqId);
					infoM.setLineNum(bo.getLineNum());
					infoM.setDateFrom(bo.getDateFrom());
					infoM.setDateTo(bo.getDateTo());
					infoM.setTypeOfRoomId(bo.getTypeOfRoomId());
					infoM.setZone(("".equals(bo.getZone())?null:bo.getZone()));
					infoM.setFloor(("".equals(bo.getFloor())?null:bo.getFloor()));
					infoM.setQtyRoomPerDay(bo.getQtyRoomPerDay());
					infoM.setGlobalTypeOfRoom(ReservConstants.GlobalTypeTypeOfRoom);
					infoM.setReservedStatus(ReservConstants.ServiceStatusReserved);
					infoM.setBookedStatus(ReservConstants.ServiceStatusBooked);
					infoM.setCheckinStatus(ReservConstants.ServiceStatusCheckin);
					infoM.setCheckoutStatus(ReservConstants.ServiceStatusCheckout);					
					getReserveOverviewDAO().genFreeRoom2Track(infoM);
					
					if(infoM.getDateRoomNotFree() != null && !"".equals(infoM.getDateRoomNotFree())){
						vo.setErrMsg(infoM.getDateRoomNotFree());
						isSuccess = false;
					}
				}
				if(isSuccess){
//					Map<String, Object> paramM = new HashMap<String, Object>();
//					paramM.put("userId", userId);
//					paramM.put("orgId", orgId);  
//					paramM.put("shiftStatus", ReservConstants.ShiftStatusOpen);
//					paramM.put("shiftTransId", shiftTransId);
//					paramM.put("sequenceId", seqId);  
//					paramM.put("groupId", seqM.getGroupId());  
//					paramM.put("serviceDate", nowDate);  
//					paramM.put("serviceStatus", serviceStatus);
					/*
					Map<String, Object> paramM = new HashMap<String, Object>();
					paramM.put("userId", userId);
					paramM.put("orgId", orgId);  
					paramM.put("shiftStatus", ReservConstants.ShiftStatusOpen);
					Integer shiftTransId = getReserveOverviewDAO().getShiftTransId(paramM);
					*/
					Integer shiftTransId = (Integer)getSessionAttribute(AppsindyConstants.S_SHIFT_TRANS_ID);
					if(shiftTransId == null){
						shiftTransId = SHIFT_TRANS_ID_DEFAULT;
						log.info("[Session] shiftTransId is null default to " + shiftTransId);
					}
					log.info("[Session] shiftTransId = " + shiftTransId);
					
					ReserveHeaderMap headerM = new ReserveHeaderMap();
					headerM.setUserId(Integer.parseInt(userId));
					headerM.setOrgId(Integer.parseInt(orgId));  
					if(shiftTransId != null && shiftTransId > 0){
						headerM.setShiftTransId(shiftTransId);
					}
					headerM.setSeqId(seqId);  
					headerM.setGroupId(seqM.getGroupId());  
					headerM.setServiceDate(nowDate);  
					headerM.setServiceStatus(serviceStatus);  
					getReserveOverviewDAO().insertReserveService4TypeOfRoom(headerM);
					//get serice header id
					serviceHeaderId = headerM.getServiceHeaderId();
				}
			}
			//set sequence id
			infoType.setSeqId(seqId);
			infoType.setServiceHeaderId(serviceHeaderId);
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return infoType;
	}	
	
	@Override
	public ReserveInfoVO getRoomRate(int groupId, Date dateFrom, Date dateTo, int typeOfRoom){
		log.info("Start ReservationServices.getRoomRate...");
		ReserveInfoVO infoVO = new ReserveInfoVO();
		RoomRateMap paramM = null;
		try{	
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			paramM = new RoomRateMap();
			paramM.setUserId(Integer.parseInt(userId));
			paramM.setOrgId(Integer.parseInt(orgId));  
			paramM.setDateFrom(dateFrom);
			paramM.setDateTo(dateTo);
			paramM.setGroupId(groupId);
			paramM.setGroupIdCustomer(ReservConstants.GroupId4Customer);
			paramM.setTypeOfRoomId(typeOfRoom);
			paramM.setDaysType(ReservConstants.GlobalTypeDaysType);
			paramM.setReservedStatus(ReservConstants.ServiceStatusReserved);
			paramM.setBookedStatus(ReservConstants.ServiceStatusBooked);
			paramM.setCheckinStatus(ReservConstants.ServiceStatusCheckin);
			paramM.setCheckoutStatus(ReservConstants.ServiceStatusCheckout);			
			getReserveOverviewDAO().getRoomRate(paramM);
			if(paramM != null){
				if(paramM.getCntRatePerRoom() > 1){
					dateTo = dateFrom;
					paramM.setDateTo(dateTo);
					getReserveOverviewDAO().getRoomRate(paramM);
					infoVO.setErrCode(-1);
				}
				infoVO.setRatePerRoom(NumberUtil.getNumberStr(paramM.getRatePerRoom(), 2));
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return infoVO;
	}		

	@Override
	public void clearTemp(int seqId){
		log.info("Start ReservationServices.clearTemp...");
		try{
			Map<String, Object> paramM = new HashMap<String, Object>();
			paramM.put("seqId", seqId);
			getReserveOverviewDAO().deleteHtServiceHeaderSeq(paramM);
			getReserveOverviewDAO().deleteHtServiceDetailTemp(paramM);
			getReserveOverviewDAO().deleteHtServiceTrackRoom(paramM);
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
	}
	
	@Override
	public ReserveInfoRoomVO selectAvailableRoom(ReserveInfoRoomVO infoRoom){
		log.info("Start ReservationServices.selectAvailableRoom...");
		try{					
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			
			int serviceHeaderId = infoRoom.getServiceHeaderId();
			Date dateFrom 		= infoRoom.getDateFrom();
			Date dateTo			= infoRoom.getDateTo();
			if(serviceHeaderId > 0){
				Info4RoomMap info4RoomMap = new Info4RoomMap();
				info4RoomMap.setServiceHeaderId(serviceHeaderId);
				info4RoomMap.setOrgId(Integer.parseInt(orgId));
				info4RoomMap.setReservedStatus(ReservConstants.ServiceStatusReserved);
				info4RoomMap.setBookedStatus(ReservConstants.ServiceStatusBooked);
				info4RoomMap.setCheckinStatus(ReservConstants.ServiceStatusCheckin);
				info4RoomMap.setCheckoutStatus(ReservConstants.ServiceStatusCheckout);
				getReserveOverviewDAO().getInfo4Room(info4RoomMap);
				
				dateFrom 	= info4RoomMap.getDateFrom();
				dateTo		= info4RoomMap.getDateTo();
				
				infoRoom.setDateFrom(dateFrom);
				infoRoom.setDateTo(dateTo);
			}
			
			infoRoom = selectAvailableRoomWithGo(infoRoom);
						
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return infoRoom;
	}	
	
	@Override
	public ReserveInfoRoomVO selectAvailableRoomWithGo(ReserveInfoRoomVO infoRoom){
		log.info("Start ReservationServices.selectAvailableRoomWithGo...");
		List<RoomVO> resultList = new ArrayList<RoomVO>();
		try{					
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			
			int serviceHeaderId = infoRoom.getServiceHeaderId();
			Date dateFrom 		= infoRoom.getDateFrom();
			Date dateTo			= infoRoom.getDateTo();
			int typeOfRoom		= infoRoom.getTypeOfRoom();
			String zone			= infoRoom.getZone();
			String floor		= infoRoom.getFloor();
			int customerId		= infoRoom.getCustomerId();
			
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("userId", userId);
			paramM.put("orgId", orgId);  
			paramM.put("dateFrom", dateFrom);
			paramM.put("dateTo", dateTo);
			paramM.put("typeOfRoom", typeOfRoom);
			paramM.put("zone", zone);
			paramM.put("floor", floor);
			paramM.put("groupId", infoRoom.getGroupInfoVO()==null?ReservConstants.GroupId4Customer:infoRoom.getGroupInfoVO().getGroupId());
			paramM.put("groupIdCustomer", ReservConstants.GroupId4Customer);
			paramM.put("daysType", ReservConstants.GlobalTypeDaysType);
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);
			getReserveOverviewDAO().generateReserveRoom(paramM);
			List<ReserveRoom> infoRoomList 	= getReserveOverviewDAO().selectGroupReserveRoom(paramM);
			List<ReserveRoom> dateList 		= getReserveOverviewDAO().selectGroupReserveRoomDate(paramM);
			List<ReserveRoom> reserveList 	= getReserveOverviewDAO().selectReserveRoom(paramM);
			GroupInfoVO groupInfo 			= getReserveOverviewDAO().selectGroupInfo(paramM);

			if(groupInfo != null){
				infoRoom.setGroupInfoVO(groupInfo);
			}
//			//v1.0
			List<RoomVO> priceList 		= null;
			RoomVO roomVO 				= null;
			RoomVO priceVO 				= null;
			int roomId 					= 0;
			String roomCode 			= "";
			int typeOfRoomId 			= 0;
			String typeOfRoomName 		= "";
			String roomZone 			= "";
			String roomFloor 			= "";
			Date _date 					= null;			
			for(ReserveRoom room : infoRoomList){
				roomVO 			= new RoomVO();
				roomId 			= room.getRoomId();
				roomCode 		= room.getRoomCode();
				typeOfRoomId 	= room.getTypeOfRoomId();
				typeOfRoomName	= room.getTypeOfRoom();
				roomZone 		= room.getRoomZone();
				roomFloor 		= room.getRoomFloor();
				roomVO.setRoomId(roomId);
				roomVO.setRoomCode(roomCode);
				roomVO.setTypeOfRoomId(typeOfRoomId);
				roomVO.setTypeOfRoom(typeOfRoomName);
				roomVO.setRoomZone(roomZone);
				roomVO.setRoomFloor(roomFloor);
				priceList 	= new ArrayList<RoomVO>();
				for(ReserveRoom date : dateList){
					priceVO 	= new RoomVO();
					_date 		= date.getGenDate();
					priceVO.setRoomId(roomId);
					priceVO.setRoomCode(roomCode);
					priceVO.setTypeOfRoomId(typeOfRoomId);
					priceVO.setTypeOfRoom(typeOfRoomName);
					priceVO.setDateGen(DateUtils.getDateStr(_date, false));
					for(ReserveRoom bo : reserveList){
						if(roomId == bo.getRoomId() && _date.compareTo(bo.getGenDate()) == 0){
							priceVO.setPrice(NumberUtil.getNumberStr(bo.getRateOfRoom(), 2));
							priceVO.setRoomStatus(bo.getRoomStatus());
							priceVO.setHeaderId(bo.getServiceHeaderId()==0?null:bo.getServiceHeaderId());
							break;
						}
					}
					priceList.add(priceVO);
				}
				roomVO.setPriceList(priceList);
				
				resultList.add(roomVO);
			}
			
			infoRoom.setResultList(resultList);
			
			if(serviceHeaderId > 0){
				//get reserve detail
				Map<String, Object> paramD = new HashMap<String, Object>();   
				paramD.put("serviceHeaderId", serviceHeaderId);
				paramD.put("customerId", customerId);
				List<ReserveDetailVO> detailList = getReserveOverviewDAO().selectReserveDetail(paramD);
				if(detailList != null && detailList.size() > 0){
					infoRoom.setDetailList(detailList);
					
					//calculate all amount
					double grandTotalAmount 	= 0;
					double sumTotalAmount		= 0;
					double sumExtraAmount		= 0;
					for(ReserveDetailVO vo : detailList){
						sumTotalAmount += StringUtils.toDouble(vo.getTotalAmount());
						sumExtraAmount += StringUtils.toDouble(vo.getExtraAmount());
					}
					grandTotalAmount		= sumTotalAmount + sumExtraAmount;
					
					infoRoom.setSumTotalAmount(NumberUtil.getNumberStr(sumTotalAmount, 2));
					infoRoom.setSumExtraAmount(NumberUtil.getNumberStr(sumExtraAmount, 2));
					infoRoom.setGrandTotalAmount(NumberUtil.getNumberStr(grandTotalAmount, 2));
				}
				
				//get information of service header
				List<ServiceHeader> headerList = getReserveOverviewDAO().selectServiceHeader(paramD);
				if(headerList != null && headerList.size() > 0){
					ServiceHeader header = headerList.get(0);
					infoRoom.setServiceStatus(header.getServiceStatus());
					infoRoom.setServiceHeaderNumber(header.getServiceHeaderNumber());
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return infoRoom;
	}	

	@Override
	public List<Info> selectGroupResultPopup(int group, String status){
		log.info("Start ReservationServices.selectGroupResultPopup...");
		List<Info> resultList = new ArrayList<Info>();
		try{
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("groupId", group);
			paramM.put("status", status);
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().selectGroupResultPopup(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}	
	@Override
	public List<Info> selectCustomerResultPopup(int customer, String status){
		log.info("Start ReservationServices.selectCustomerResultPopup...");
		List<Info> resultList = new ArrayList<Info>();
		try{
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("customerId", customer);
			paramM.put("status", status);
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().selectCustomerResultPopup(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}
	@Override
	public List<Info> selectRoomResultPopup(int room, String status){
		log.info("Start ReservationServices.selectRoomResultPopup...");
		List<Info> resultList = new ArrayList<Info>();
		try{
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("roomId", room);
			paramM.put("status", status);
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().selectRoomResultPopup(paramM);
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return resultList;
	}

	@Override
	public List<CustomerVO> getCustomerTreeList(int serviceHeaderId){
		log.info("Start ReservationServices.getCustomerTreeList...");
		List<CustomerVO> resultList = new ArrayList<CustomerVO>();
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("userId", userId);  
			paramM.put("orgId", orgId);  
			paramM.put("serviceHeaderId", serviceHeaderId);
			getReserveOverviewDAO().generateCustomerTreeList(paramM);
			List<CustomerVO> tmpList = getReserveOverviewDAO().selectCustomerTreeList(paramM);
			if(tmpList != null && tmpList.size() > 0){
				CustomerVO vo 		= null; 
				int customerId 		= 0;
				String customerName = "";
				int roomId 			= 0;
				String roomCode 	= "";
				ArrayList<RoomVO> roomList = null;
				RoomVO roomVO = null;
				for(CustomerVO customerVO : tmpList){
					customerId 		= customerVO.getCustomerId();
					customerName 	= customerVO.getCustomerName();
					roomId 			= customerVO.getRoomId();
					roomCode 		= customerVO.getRoomCode();
					
					if(customerName != null && !"".equals(customerName)){
						vo 			= new CustomerVO();
						vo.setCustomerId(customerId);
						vo.setCustomerName(customerName);
						
						roomList 	= new ArrayList<RoomVO>();
						vo.setRoomList(roomList);
						
						resultList.add(vo);
						continue;
					}else{
						roomVO = new RoomVO();
						roomVO.setRoomId(roomId);
						roomVO.setRoomCode(roomCode);
						vo.getRoomList().add(roomVO);
					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return resultList;
	}
	@Override
	public List<Combo> getItemCombos(){
		log.info("Start ReservationServices.getItemCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getItemCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}
	
	@Override
	public ReserveDetailVO getReserveDetail(ReserveDetailVO detailVO, int groupId){
		log.info("Start ReservationServices.getReserveDetail...");
		try{	
			if(detailVO == null) detailVO = new ReserveDetailVO();
			//get reserve detail
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("groupId", groupId);
			GroupInfoVO groupInfo 	= getReserveOverviewDAO().selectGroupInfo(paramM);			
			detailVO.setGroupInfoVO(groupInfo);			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return detailVO;
	}		
	@Override
	public ReserveDetailVO getReserveDetailById(int groupId, int serviceDetailId){
		log.info("Start ReservationServices.getReserveDetailById...");
		ReserveDetailVO detailVO = new ReserveDetailVO();
		try{	
//			String userId 	= getSession().get(S_USERLOGIN)==null?USERLOGIN_DEFAULT:(String)getSession().get(S_USERLOGIN);
//			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			//get reserve detail
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("groupId", groupId);
			paramM.put("serviceDetailId", serviceDetailId);
			GroupInfoVO groupInfo 				= getReserveOverviewDAO().selectGroupInfo(paramM);			
			List<ReserveDetailVO> detailList 	= getReserveOverviewDAO().selectReserveDetail(paramM);
			if(detailList != null && detailList.size() > 0){
				detailVO = detailList.get(0);
			}
			if(detailVO == null) detailVO = new ReserveDetailVO();
			List<ItemVO> itemList				= getReserveOverviewDAO().selectReserveDetailItem(paramM);
			if(itemList != null && itemList.size() > 0){
				detailVO.setItemList(itemList);
			}
			detailVO.setGroupInfoVO(groupInfo);			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return detailVO;
	}	
	@Override
	public ReserveDetailVO getReserveDetailByRoomId(int groupId, int typeOfRoomId, int roomId, Date dateGen){
		log.info("Start ReservationServices.getReserveDetailByRoomId...");
		ReserveDetailVO detailVO = new ReserveDetailVO();
		try{	
			Calendar c = Calendar.getInstance(Locale.US);
			c.setTime(dateGen);
			c.add(Calendar.DATE, 1);
			Date nextDate = c.getTime();
			//get reserve detail
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("groupId", groupId);
			GroupInfoVO groupInfo 		= getReserveOverviewDAO().selectGroupInfo(paramM);			
			detailVO.setGroupInfoVO(groupInfo);			
			detailVO.setTypeOfRoomId(""+typeOfRoomId);
			detailVO.setRoomNo(""+roomId);
			detailVO.setServiceStartDate(DateUtils.getDateStr(dateGen, false));
			detailVO.setServiceEndDate(DateUtils.getDateStr(nextDate, false));
			detailVO.setDay("1");
			ReserveInfoVO reserveInfoVO = getDetailRoomRate(groupId, dateGen, nextDate, typeOfRoomId, roomId);
			if(reserveInfoVO != null){
				detailVO.setRatePerRoom(reserveInfoVO.getRatePerRoom());
				detailVO.setTotalAmount(reserveInfoVO.getRatePerRoom());
			}
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return detailVO;
	}	
	
	@Override
	public CustomerVO getCustomerById(int customerId){
		log.info("Start ReservationServices.getCustomerById...");
		CustomerVO customerVO = new CustomerVO();
		try{	
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);
			paramM.put("customerId", customerId);
			List<CustomerVO> customerList = getReserveOverviewDAO().getCustomerById(paramM);
			if(customerList != null && customerList.size() > 0){
				customerVO = customerList.get(0);
			}			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return customerVO;
	}
	
	@Override
	public CustomerVO getCustomerViewById(int paymentId, int customerId){
		log.info("Start ReservationServices.getCustomerViewById...");
		CustomerVO customerVO = new CustomerVO();
		try{	
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("paymentId", paymentId);
			paramM.put("customerId", customerId);
			List<CustomerVO> customerList = getReserveOverviewDAO().getCustomerByPaymentId(paramM);
			if(customerList != null && customerList.size() > 0){
				customerVO = customerList.get(0);
			}			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return customerVO;
	}

	@Override
	public List<Combo> getRoomCombosByTypeOfRoom(int typeOfRoomId, Date dateFrom, Date dateTo){
		log.info("Start ReservationServices.getRoomCombosByTypeOfRoom...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);  
			paramM.put("typeOfRoomId", typeOfRoomId);   
			paramM.put("dateFrom", dateFrom);   
			paramM.put("dateTo", dateTo);   
			resultList = getReserveOverviewDAO().getRoomCombosByTypeOfRoom(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}	

	@Override
	public ReserveInfoVO getDetailRoomRate(int groupId, Date dateFrom, Date dateTo, int typeOfRoom, int roomId){
		log.info("Start ReservationServices.getDetailRoomRate...");
		ReserveInfoVO infoVO = new ReserveInfoVO();
		RoomRateMap paramM = null;
		try{	
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			paramM = new RoomRateMap();
			paramM.setUserId(Integer.parseInt(userId));
			paramM.setOrgId(Integer.parseInt(orgId));  
			paramM.setDateFrom(dateFrom);
			paramM.setDateTo(dateTo);
			paramM.setGroupId(groupId);
			paramM.setGroupIdCustomer(ReservConstants.GroupId4Customer);
			paramM.setRoomId(roomId);
			paramM.setTypeOfRoomId(typeOfRoom);
			paramM.setDaysType(ReservConstants.GlobalTypeDaysType);
			paramM.setReservedStatus(ReservConstants.ServiceStatusReserved);
			paramM.setBookedStatus(ReservConstants.ServiceStatusBooked);
			paramM.setCheckinStatus(ReservConstants.ServiceStatusCheckin);
			paramM.setCheckoutStatus(ReservConstants.ServiceStatusCheckout);			
			getReserveOverviewDAO().getDetailRoomRate(paramM);
			if(paramM != null){
				if(paramM.getCntRatePerRoom() > 1){
					dateTo = dateFrom;
					paramM.setDateTo(dateTo);
					getReserveOverviewDAO().getRoomRate(paramM);
					infoVO.setErrCode(-1);
				}
				infoVO.setRatePerRoom(NumberUtil.getNumberStr(paramM.getRatePerRoom(), 2));
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return infoVO;
	}		
	
	@Override
	public ReserveDetailVO saveReserveDetail(ReserveDetailVO reserveDetailVO){
		log.info("Start ReservationServices.saveReserveDetail...");
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			
			int groupId 		= reserveDetailVO.getGroupInfoVO()==null?0:reserveDetailVO.getGroupInfoVO().getGroupId();
			int serviceHeaderId = reserveDetailVO.getServiceHeaderId()==null||"".equals(reserveDetailVO.getServiceHeaderId())?0:Integer.parseInt(reserveDetailVO.getServiceHeaderId());			
			int serviceDetailId	= reserveDetailVO.getServiceDetailId()==null||"".equals(reserveDetailVO.getServiceDetailId())?0:Integer.parseInt(reserveDetailVO.getServiceDetailId());
			String serviceStatus= reserveDetailVO.getServiceStatus()==null||"".equals(reserveDetailVO.getServiceStatus())?ReservConstants.ServiceStatusReserved:reserveDetailVO.getServiceStatus();
			
			Date nowDate = new Date();
			if(serviceHeaderId == 0){
				//call get service header id
				Map<String, Object> paramM = new HashMap<String, Object>();
				paramM.put("userId", userId);
				paramM.put("orgId", orgId);  
				paramM.put("shiftStatus", ReservConstants.ShiftStatusOpen);
				Integer shiftTransId = getReserveOverviewDAO().getShiftTransId(paramM);
				
				ReserveHeaderMap headerM = new ReserveHeaderMap();
				headerM.setUserId(Integer.parseInt(userId));
				headerM.setOrgId(Integer.parseInt(orgId));  
				if(shiftTransId != null && shiftTransId > 0){
					headerM.setShiftTransId(shiftTransId);
				}
				headerM.setGroupId(groupId);  
				headerM.setServiceDate(nowDate);  
				headerM.setServiceStatus(serviceStatus);  
				getReserveOverviewDAO().getServiceHeader(headerM);
				//get serice header id
				serviceHeaderId = headerM.getServiceHeaderId();				
			}
			//insert/update service detail
			ReserveDetail reserveDetail = new ReserveDetail();
			reserveDetail.setUserId(Integer.parseInt(userId));
			reserveDetail.setOrgId(Integer.parseInt(orgId));
//			reserveDetail.setSeqId(seqId);
			reserveDetail.setServiceHeaderId(serviceHeaderId);
			reserveDetail.setServiceDetailId(serviceDetailId);
			reserveDetail.setServiceDetailLine(StringUtils.toInt(reserveDetailVO.getServiceDetailLine()));
			reserveDetail.setServiceStatus(serviceStatus);
			reserveDetail.setServiceStartDate(DateUtils.createDate(reserveDetailVO.getServiceStartDate(), false));
			reserveDetail.setServiceEndDate(DateUtils.createDate(reserveDetailVO.getServiceEndDate(), false));
			reserveDetail.setCustomerId(StringUtils.toInt(reserveDetailVO.getCustomerId()));
			reserveDetail.setRoomId(StringUtils.toInt(reserveDetailVO.getRoomNo()));
			reserveDetail.setTypeOfRoomId(StringUtils.toInt(reserveDetailVO.getTypeOfRoomId()));
			reserveDetail.setTypeOfRoom(reserveDetailVO.getTypeOfRoom());
			reserveDetail.setRoomZone(reserveDetailVO.getRoomZone());
			reserveDetail.setRoomFloor(reserveDetailVO.getRoomFloor());
			reserveDetail.setDaysRange(StringUtils.toInt(reserveDetailVO.getDay()));
			reserveDetail.setRatePerRoom(StringUtils.toDouble(reserveDetailVO.getRatePerRoom()));
			reserveDetail.setTotalAmount(StringUtils.toDouble(reserveDetailVO.getTotalAmount()));
			reserveDetail.setBreakfast(reserveDetailVO.getBreakfast());
			reserveDetail.setBreakfastCoupon(reserveDetailVO.getBreakfastCoupon());
			reserveDetail.setNumOfAdult(StringUtils.toInt(reserveDetailVO.getNumOfAdult()));
			reserveDetail.setNumOfChild(StringUtils.toInt(reserveDetailVO.getNumOfChild()));
			//set for check freeroom2track
			reserveDetail.setGlobalTypeOfRoom(ReservConstants.GlobalTypeTypeOfRoom);
			reserveDetail.setReservedStatus(ReservConstants.ServiceStatusReserved);
			reserveDetail.setBookedStatus(ReservConstants.ServiceStatusBooked);
			reserveDetail.setCheckinStatus(ReservConstants.ServiceStatusCheckin);
			reserveDetail.setCheckoutStatus(ReservConstants.ServiceStatusCheckout);		
			if(serviceDetailId > 0){
				getReserveOverviewDAO().updateReserveDetail(reserveDetail); 
				serviceDetailId = reserveDetail.getServiceDetailId();
			}else{
				getReserveOverviewDAO().insertReserveDetail(reserveDetail); 
				serviceDetailId = reserveDetail.getServiceDetailId();
			}
			if(reserveDetail.getDateRoomNotFree() != null && !"".equals(reserveDetail.getDateRoomNotFree())){
				reserveDetailVO.setErrMsg(reserveDetail.getDateRoomNotFree());
			}
			if(serviceDetailId > 0){
				//clear detail item
				Map<String, Object> paramM = new HashMap<String, Object>();
				paramM.put("serviceDetailId", serviceDetailId);
				getReserveOverviewDAO().clearReserveDetailItem(paramM);
				//loop insert item
				ReserveItem item = null;
				List<ItemVO> itemList = reserveDetailVO.getItemList();
				for(ItemVO itemVO : itemList){
					item = new ReserveItem();
					item.setUserId(Integer.parseInt(userId));
					item.setOrgId(Integer.parseInt(orgId));
					item.setServiceDetailId(serviceDetailId);
					item.setServiceHeaderId(serviceHeaderId);
					item.setLineNum(StringUtils.toInt(itemVO.getLineNum()));
					item.setItemId(StringUtils.toInt(itemVO.getItemId()));
					item.setItemQty(StringUtils.toInt(itemVO.getItemQty()));
					item.setUnitPrice(StringUtils.toDouble(itemVO.getUnitPrice()));
					item.setTotalAmount(StringUtils.toDouble(itemVO.getTotalAmount()));
					getReserveOverviewDAO().insertReserveItem(item);
				}
							
//				GenFreeRoom2TrackMap infoM = new GenFreeRoom2TrackMap();
//				infoM.setUserId(Integer.parseInt(userId));
//				infoM.setOrgId(Integer.parseInt(orgId));
//				infoM.setServiceDate(nowDate);
//				infoM.setServiceStatus(serviceStatus);
//				infoM.setServiceHeaderId(serviceHeaderId);
//				infoM.setServiceDetailId(serviceDetailId);
//				infoM.setLineNum(reserveDetail.getServiceDetailLine());
//				infoM.setRoomId(reserveDetail.getRoomId());
//				infoM.setDateFrom(reserveDetail.getServiceStartDate());
//				infoM.setDateTo(reserveDetail.getServiceEndDate());
//				infoM.setTypeOfRoomId(reserveDetail.getTypeOfRoomId());
//				infoM.setGlobalTypeOfRoom(ReservConstants.GlobalTypeTypeOfRoom);
//				infoM.setReservedStatus(ReservConstants.ServiceStatusReserved);
//				infoM.setBookedStatus(ReservConstants.ServiceStatusBooked);
//				infoM.setCheckinStatus(ReservConstants.ServiceStatusCheckin);
//				infoM.setCheckoutStatus(ReservConstants.ServiceStatusCheckout);		
//				
//				System.out.println("## "+BeanUtils.describe(infoM));
//				
//				getReserveOverviewDAO().freeRoom2Track(infoM);
//				
//				if(infoM.getDateRoomNotFree() != null && !"".equals(infoM.getDateRoomNotFree())){
////					vo.setErrMsg(infoM.getDateRoomNotFree());
////					isSuccess = false;
//				}				
			}
			reserveDetailVO.setServiceHeaderId(""+serviceHeaderId);
			reserveDetailVO.setServiceDetailId(""+serviceDetailId);
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return reserveDetailVO;
	}
	@Override
	public List<Combo> getTitleCombos(){
		log.info("Start ReservationServices.getTitleCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeName", ReservConstants.GlobalTypeCustomerTitle);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}	
	@Override
	public List<Combo> getGenderCombos(){
		log.info("Start ReservationServices.getGenderCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeName", ReservConstants.GlobalTypeGender);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}	
	@Override
	public List<Combo> getProvinceCombos(){
		log.info("Start ReservationServices.getProvinceCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeName", ReservConstants.GlobalTypeProvince);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getProvinceCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}	
	@Override
	public List<Combo> getNationalityCombos(){
		log.info("Start ReservationServices.getNationalityCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeName", ReservConstants.GlobalTypeNationality);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}
	
	@Override
	public CustomerVO addCustomer(CustomerVO customerVO){
		log.info("Start ReservationServices.addCustomer...");
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			
			customerVO.setUserId(Integer.parseInt(userId));
			customerVO.setOrgId(Integer.parseInt(orgId));
			customerVO.setStartDate(new Date());
			getReserveOverviewDAO().insertCustomer(customerVO);
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return customerVO;
	}

	@Override
	public CustomerVO editCustomer(CustomerVO customerVO){
		log.info("Start ReservationServices.editCustomer...");
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			
			customerVO.setUserId(Integer.parseInt(userId));
			customerVO.setOrgId(Integer.parseInt(orgId));
			customerVO.setStartDate(new Date());
			getReserveOverviewDAO().updateCustomer(customerVO);
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return customerVO;
	}

	@Override
	public ReserveInfoRoomVO processReserveRoom(ReserveInfoRoomVO infoRoom, String serviceStatus){
		log.info("Start ReservationServices.processReserveRoom...");
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
						
			int serviceHeaderId = infoRoom.getServiceHeaderId();
			List<ReserveDetailVO> detailList = infoRoom.getDetailList();
			Map<String, Object> paramM = null;
			for(ReserveDetailVO vo : detailList){
				paramM = new HashMap<String, Object>();
				paramM.put("userId", userId);
				paramM.put("orgId", orgId);  
				paramM.put("serviceHeaderId", serviceHeaderId);
				paramM.put("serviceDetailId", Integer.parseInt(vo.getServiceDetailId()));
				paramM.put("serviceStatus", serviceStatus);
				paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
				paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
				paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
				paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);
				paramM.put("paymentStatus", ReservConstants.ServiceStatusPayment);
				paramM.put("clearStatus", ReservConstants.ServiceStatusClear);
				paramM.put("changeBackStatus", ReservConstants.AuthorizeChangbackStatus);
				getReserveOverviewDAO().updateServiceStatus4Room(paramM);
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return infoRoom;
	}
	
	@Override
	public List<CustomerVO> getCustomerVOCombos(){
		log.info("Start ReservationServices.getCustomerVOCombos...");
		List<CustomerVO> resultList = new ArrayList<CustomerVO>();
		try{	
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);
			resultList = getReserveOverviewDAO().getCustomerById(paramM);	
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return resultList;
	}	

	@Override
	public List<CustomerVO> getCustomerPaymentCombos(int paymentId){
		log.info("Start ReservationServices.getCustomerPaymentCombos...");
		List<CustomerVO> resultList = new ArrayList<CustomerVO>();
		try{	
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("paymentId", paymentId);
			resultList = getReserveOverviewDAO().getCustomerByPaymentId(paramM);	
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return resultList;
	}	

	@Override
	public ReservePaymentVO saveReservePayment(ReservePaymentVO reservePaymentVO){
		log.info("Start ReservationServices.saveReservePayment...");
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 			= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			
			Integer shiftTransId = (Integer)getSessionAttribute(AppsindyConstants.S_SHIFT_TRANS_ID);
			if(shiftTransId == null){
				shiftTransId = SHIFT_TRANS_ID_DEFAULT;
			}
			
			int servicePaymentId 	= reservePaymentVO.getServicePaymentId();
			int serviceHeaderId 	= reservePaymentVO.getServiceHeaderId();
			Date nowDate 			= new Date();
			
			ReservePayment reservePayment = new ReservePayment();
			reservePayment.setServicePaymentId(servicePaymentId);
			reservePayment.setUserId(StringUtils.toInt(userId));
		    reservePayment.setOrgId(StringUtils.toInt(orgId));
		    reservePayment.setServiceHeaderId(serviceHeaderId);
		    reservePayment.setPaymentDate(nowDate);
		    reservePayment.setTotalAmount(StringUtils.toDouble(reservePaymentVO.getTotalAmt()));
		    reservePayment.setExtraAmount(StringUtils.toDouble(reservePaymentVO.getExtraAmt()));
		    reservePayment.setTipAmount(StringUtils.toDouble(reservePaymentVO.getTip()));
		    reservePayment.setDiscountAmount(StringUtils.toDouble(reservePaymentVO.getDiscountAmt()));
		    reservePayment.setAuthorizedBy(StringUtils.toInt(reservePaymentVO.getAuthorizedBy()));
		    reservePayment.setChangeAmount(StringUtils.toDouble(reservePaymentVO.getChangeAmt()));		
		    
		    //clear all before save
			Payment2Shift payment2Shift	= null;
			Map<String, Object> paramD = new HashMap<String, Object>();   
			paramD.put("serviceHeaderId", serviceHeaderId);
			List<ReservePaymentDetailVO> paymentDetailList = getReserveOverviewDAO().selectReservePaymentDetail(paramD);
			if(paymentDetailList != null && paymentDetailList.size() > 0){
				for(ReservePaymentDetailVO vo : paymentDetailList){
					paramD.put("paymentDetailId", vo.getServicePaymentDetailId());
					//check owner of payment method
					if(shiftTransId == vo.getShiftTransId()){
						getReserveOverviewDAO().clearReservePaymentDetailById(paramD);
	
						payment2Shift = new Payment2Shift();
						payment2Shift.setUserId(StringUtils.toInt(userId));			
						payment2Shift.setOrgId(StringUtils.toInt(orgId));			
						payment2Shift.setShiftTransId(shiftTransId);
						payment2Shift.setServicePaymentDetailId(vo.getServicePaymentDetailId());				
						getReserveOverviewDAO().deletePayment2Shift(payment2Shift);		
					}
				}		
			}
			//check case insert/update
			if(servicePaymentId > 0){	//update
				getReserveOverviewDAO().updateReservePayment(reservePayment); 
			}else{						//insert
				getReserveOverviewDAO().clearReservePaymentDetail(reservePayment); 
				getReserveOverviewDAO().clearReservePayment(reservePayment); 
				
				//insert reserve payment master
				getReserveOverviewDAO().insertReservePayment(reservePayment); 
				servicePaymentId = reservePayment.getServicePaymentId();
			}
			
			//insert reserve payment detail
			int index = 0;
			ReservePaymentDetail reservePaymentDetail 	= null;
			List<ReservePaymentDetailVO> detailList = reservePaymentVO.getPaymentMethodList();			
			for(ReservePaymentDetailVO detailVO : detailList){
				if(detailVO.getShiftTransId() == 0 || shiftTransId == detailVO.getShiftTransId()){
					reservePaymentDetail = new ReservePaymentDetail();
	
					reservePaymentDetail.setServicePaymentId(servicePaymentId);
					reservePaymentDetail.setUserId(StringUtils.toInt(userId));
					reservePaymentDetail.setOrgId(StringUtils.toInt(orgId));
					reservePaymentDetail.setServiceHeaderId(serviceHeaderId);
					reservePaymentDetail.setServiceDetailId(detailVO.getServiceDetailId()==null||"0".equals(detailVO.getServiceDetailId())?null:StringUtils.toInt(detailVO.getServiceDetailId()));
					reservePaymentDetail.setPaymentLineNum(++index);
					reservePaymentDetail.setPaymentMethodId(StringUtils.toInt(detailVO.getPaymentMethodId()));
					reservePaymentDetail.setReferenceNumber(detailVO.getRefNo());
					reservePaymentDetail.setPaymentAmount(StringUtils.toDouble(detailVO.getAmount()));	
					getReserveOverviewDAO().insertReservePaymentDetail(reservePaymentDetail);
					
					payment2Shift = new Payment2Shift();
					payment2Shift.setUserId(StringUtils.toInt(userId));
					payment2Shift.setOrgId(StringUtils.toInt(orgId));
					payment2Shift.setShiftTransId(shiftTransId);
					payment2Shift.setServicePaymentDetailId(reservePaymentDetail.getServicePaymentDetailId());
					payment2Shift.setPaymentMethodName(detailVO.getPaymentMethodName());
				log.info("insertPayment2Shift - PaymentMethodName = " + detailVO.getPaymentMethodName());
					payment2Shift.setReferenceNumber(detailVO.getRefNo());
					payment2Shift.setRoomNo(detailVO.getRoomNo());
					payment2Shift.setPaymentDate(nowDate);
					payment2Shift.setPaymentAmount(StringUtils.toDouble(detailVO.getAmount()));
	                payment2Shift.setGlobalTypeShiftTransType(ReservConstants.GlobalTypeShiftTransType);
	                payment2Shift.setShiftTransTypeIn(ReservConstants.ShiftTransTypeIn);
	                payment2Shift.setGlobalTypeShiftTransSource(ReservConstants.GlobalTypeShiftTransSource);
	                payment2Shift.setShiftTransSourceSystem(ReservConstants.ShiftTransSourceSystem);
					getReserveOverviewDAO().insertPayment2Shift(payment2Shift);
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return reservePaymentVO;
	}

	@Override
	public ReservePaymentVO confirmReservePayment(ReservePaymentVO reservePaymentVO){
		log.info("Start ReservationServices.confirmReservePayment...");
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId = user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 			= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			
			Integer shiftTransId = (Integer)getSessionAttribute(AppsindyConstants.S_SHIFT_TRANS_ID);
			if(shiftTransId == null){
				shiftTransId = SHIFT_TRANS_ID_DEFAULT;
			}
			
			int servicePaymentId 	= reservePaymentVO.getServicePaymentId();
			int serviceHeaderId 	= reservePaymentVO.getServiceHeaderId();
			Date nowDate 			= new Date();
			
			ReservePayment reservePayment = new ReservePayment();
			reservePayment.setServicePaymentId(servicePaymentId);
			reservePayment.setUserId(StringUtils.toInt(userId));
		    reservePayment.setOrgId(StringUtils.toInt(orgId));
		    reservePayment.setServiceHeaderId(serviceHeaderId);
		    reservePayment.setPaymentDate(nowDate);
		    reservePayment.setTotalAmount(StringUtils.toDouble(reservePaymentVO.getTotalAmt()));
		    reservePayment.setExtraAmount(StringUtils.toDouble(reservePaymentVO.getExtraAmt()));
		    reservePayment.setTipAmount(StringUtils.toDouble(reservePaymentVO.getTip()));
		    reservePayment.setDiscountAmount(StringUtils.toDouble(reservePaymentVO.getDiscountAmt()));
		    reservePayment.setAuthorizedBy(StringUtils.toInt(reservePaymentVO.getAuthorizedBy()));
		    reservePayment.setChangeAmount(StringUtils.toDouble(reservePaymentVO.getChangeAmt()));			
		    
		    //clear all before save
			Payment2Shift payment2Shift	= null;
			Map<String, Object> paramD = new HashMap<String, Object>();   
			paramD.put("serviceHeaderId", serviceHeaderId);
			List<ReservePaymentDetailVO> paymentDetailList = getReserveOverviewDAO().selectReservePaymentDetail(paramD);
			if(paymentDetailList != null && paymentDetailList.size() > 0){
				for(ReservePaymentDetailVO vo : paymentDetailList){
					paramD.put("paymentDetailId", vo.getServicePaymentDetailId());
					//check owner of payment method
					if(shiftTransId == vo.getShiftTransId()){
						getReserveOverviewDAO().clearReservePaymentDetailById(paramD);
	
						payment2Shift = new Payment2Shift();
						payment2Shift.setUserId(StringUtils.toInt(userId));			
						payment2Shift.setOrgId(StringUtils.toInt(orgId));			
						payment2Shift.setShiftTransId(shiftTransId);			
						payment2Shift.setServicePaymentDetailId(vo.getServicePaymentDetailId());				
						getReserveOverviewDAO().deletePayment2Shift(payment2Shift);
					}
				}		
			}
			
			//check case insert/update
			if(servicePaymentId > 0){	//update
				getReserveOverviewDAO().updateReservePayment(reservePayment); 
			}else{						//insert
				getReserveOverviewDAO().clearReservePaymentDetail(reservePayment); 
				getReserveOverviewDAO().clearReservePayment(reservePayment); 
	
				getReserveOverviewDAO().insertReservePayment(reservePayment); 
				servicePaymentId = reservePayment.getServicePaymentId();
				reservePaymentVO.setServicePaymentId(servicePaymentId);
			}
			
			//insert payment detail
			int index = 0;
			Map<String, Object> paramM = null;
			ReservePaymentDetail reservePaymentDetail = null;
			List<ReservePaymentDetailVO> detailList = reservePaymentVO.getPaymentMethodList();	
			if(detailList != null){
				for(ReservePaymentDetailVO detailVO : detailList){
					if(detailVO.getShiftTransId() == 0 || shiftTransId == detailVO.getShiftTransId()){
						reservePaymentDetail = new ReservePaymentDetail();
		
						reservePaymentDetail.setServicePaymentId(servicePaymentId);
						reservePaymentDetail.setUserId(StringUtils.toInt(userId));
						reservePaymentDetail.setOrgId(StringUtils.toInt(orgId));
						reservePaymentDetail.setServiceHeaderId(serviceHeaderId);
						reservePaymentDetail.setServiceDetailId(detailVO.getServiceDetailId()==null||"0".equals(detailVO.getServiceDetailId())?null:StringUtils.toInt(detailVO.getServiceDetailId()));
						reservePaymentDetail.setPaymentLineNum(++index);
						reservePaymentDetail.setPaymentMethodId(StringUtils.toInt(detailVO.getPaymentMethodId()));
						reservePaymentDetail.setReferenceNumber(detailVO.getRefNo());
						reservePaymentDetail.setPaymentAmount(StringUtils.toDouble(detailVO.getAmount()));	
						getReserveOverviewDAO().insertReservePaymentDetail(reservePaymentDetail);
						
						payment2Shift = new Payment2Shift();
						payment2Shift.setUserId(StringUtils.toInt(userId));
						payment2Shift.setOrgId(StringUtils.toInt(orgId));
						payment2Shift.setShiftTransId(shiftTransId);
						payment2Shift.setServicePaymentDetailId(reservePaymentDetail.getServicePaymentDetailId());
						payment2Shift.setPaymentMethodName(detailVO.getPaymentMethodName());
						payment2Shift.setReferenceNumber(detailVO.getRefNo());
						payment2Shift.setRoomNo(detailVO.getRoomNo());
						payment2Shift.setPaymentDate(nowDate);
						payment2Shift.setPaymentAmount(StringUtils.toDouble(detailVO.getAmount()));
		                payment2Shift.setGlobalTypeShiftTransType(ReservConstants.GlobalTypeShiftTransType);
		                payment2Shift.setShiftTransTypeIn(ReservConstants.ShiftTransTypeIn);
		                payment2Shift.setGlobalTypeShiftTransSource(ReservConstants.GlobalTypeShiftTransSource);
		                payment2Shift.setShiftTransSourceSystem(ReservConstants.ShiftTransSourceSystem);
						getReserveOverviewDAO().insertPayment2Shift(payment2Shift);
					}
				}
			}
			
			//call procedure for change status
			paramM = new HashMap<String, Object>();
			paramM.put("serviceHeaderId", serviceHeaderId);
			String[] arrDetailId = reservePaymentVO.getArrServiceDetailId().split(",");
			for(String detailId : arrDetailId){
				paramM = new HashMap<String, Object>();
				paramM.put("userId", userId);
				paramM.put("orgId", orgId);  
				paramM.put("serviceHeaderId", serviceHeaderId);
				paramM.put("serviceDetailId", detailId);
				paramM.put("serviceStatus", ReservConstants.ServiceStatusPayment);
				paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
				paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
				paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
				paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);
				paramM.put("paymentStatus", ReservConstants.ServiceStatusPayment);
				paramM.put("clearStatus", ReservConstants.ServiceStatusClear);
				paramM.put("changeBackStatus", ReservConstants.AuthorizeChangbackStatus);
				getReserveOverviewDAO().updateServiceStatus4Room(paramM);	
				
				paramM.put("servicePaymentId", servicePaymentId);
				getReserveOverviewDAO().updatePayment4ServiceDetail(paramM);	
								
			}
	
		} catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return reservePaymentVO;
	}
	@Override
	public ReservePaymentVO selectReservePayment(ReservePaymentVO paymentVO){
		log.info("Start ReservationServices.selectReservePayment...");
		try{					
			int groupId 		= paymentVO.getGroupInfoVO()==null?ReservConstants.GroupId4Customer:paymentVO.getGroupInfoVO().getGroupId();
			int serviceHeaderId = paymentVO.getServiceHeaderId();
			
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("groupId", groupId);
			GroupInfoVO groupInfo 			= getReserveOverviewDAO().selectGroupInfo(paramM);

			if(groupInfo != null){
				paymentVO.setGroupInfoVO(groupInfo);
			}
			
			if(serviceHeaderId > 0){
				Map<String, Object> paramD = new HashMap<String, Object>();   
				paramD.put("serviceHeaderId", serviceHeaderId);
				//get reserve payment
				double tip 		= 0;
				double discount	= 0;
				List<ReservePaymentVO> paymentList = getReserveOverviewDAO().selectReservePayment(paramD);
				if(paymentList != null && paymentList.size() > 0){
					ReservePaymentVO tmpPay = paymentList.get(0);

					tip 		= StringUtils.toDouble(tmpPay.getTip());
					discount 	= StringUtils.toDouble(tmpPay.getDiscountAmt());
					
					paymentVO.setServicePaymentId(tmpPay.getServicePaymentId());
					paymentVO.setTip(tmpPay.getTip());
					paymentVO.setDiscountAmt(tmpPay.getDiscountAmt());
					paymentVO.setAuthorizedBy(tmpPay.getAuthorizedBy());
					paymentVO.setAuthorizedByName(tmpPay.getAuthorizedByName());
//					paymentVO.setRemainingAmt(tmpPay.getRemainingAmt());
					paymentVO.setChangeAmt(tmpPay.getChangeAmt());
				}				
				
				
				//get reserve detail
				//paramD.put("arrServiceDetailId", paymentVO.getArrServiceDetailId());
//				paramD.put("arrServiceDetailId", new int[]{39, 40, 41});
				List<ReserveDetailVO> detailList = new ArrayList<ReserveDetailVO>();
				String[] arrDetailId = paymentVO.getArrServiceDetailId().split(",");
				for(String detailId : arrDetailId){
					paramD.put("serviceDetailId", detailId);
					List<ReserveDetailVO> tmpList = getReserveOverviewDAO().selectReserveDetail(paramD);
					if(tmpList != null && tmpList.size() > 0){
						detailList.add(tmpList.get(0));
					}
				}
				
//				List<ReserveDetailVO> detailList = getReserveOverviewDAO().selectReserveDetail(paramD);
				double sumTotalAmount		= 0;
				double sumExtraAmount		= 0;
				double sumNetAmount			= 0;
				if(detailList != null && detailList.size() > 0){
					paymentVO.setDetailList(detailList);
					
					//calculate all amount
					for(ReserveDetailVO vo : detailList){
						sumTotalAmount += StringUtils.toDouble(vo.getTotalAmount());
						sumExtraAmount += StringUtils.toDouble(vo.getExtraAmount());
						sumNetAmount   += StringUtils.toDouble(vo.getNetAmount());
					}
					
					paymentVO.setSumTotalAmount(NumberUtil.getNumberStr(sumTotalAmount, 2));
					paymentVO.setSumExtraAmount(NumberUtil.getNumberStr(sumExtraAmount, 2));
					paymentVO.setSumNetAmount(NumberUtil.getNumberStr(sumNetAmount, 2));
				}
				List<ReservePaymentDetailVO> paymentDetailList = getReserveOverviewDAO().selectReservePaymentDetail(paramD);
				if(paymentDetailList != null && paymentDetailList.size() > 0){
					paymentVO.setPaymentMethodList(paymentDetailList);
					
					//calculate all amount
					double sumAmount		= 0;
					for(ReservePaymentDetailVO vo : paymentDetailList){
						sumAmount += StringUtils.toDouble(vo.getAmount());
					}					
					paymentVO.setSumAmount(NumberUtil.getNumberStr(sumAmount, 2));
					
					double remainingAmt = sumTotalAmount + sumExtraAmount + tip - sumAmount - discount;
					paymentVO.setRemainingAmt(NumberUtil.getNumberStr(remainingAmt, 2));
					
				}				
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return paymentVO;
	}	
	
	@Override
	public List<Combo> getPaymentMethodCombos(){
		log.info("Start ReservationServices.getPaymentMethodCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("typeName", ReservConstants.GlobalTypePaymentMethod);   
			paramM.put("orgId", orgId);  
			resultList = getReserveOverviewDAO().getCombos(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}	
	@Override
	public List<Combo> getRoomByHeaderCombos(int serviceHeaderId){
		log.info("Start ReservationServices.getRoomByHeaderCombos...");
		List<Combo> resultList = new ArrayList<Combo>();
		try{
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("serviceHeaderId", serviceHeaderId);   
			paramM.put("orgId", orgId);  
			paramM.put("reservedStatus", ReservConstants.ServiceStatusReserved);
			paramM.put("bookedStatus", ReservConstants.ServiceStatusBooked);
			paramM.put("checkinStatus", ReservConstants.ServiceStatusCheckin);
			paramM.put("checkoutStatus", ReservConstants.ServiceStatusCheckout);			
			resultList = getReserveOverviewDAO().getRoomCombosByHeader(paramM);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return resultList;
	}	

	@Override
	public ReserveDetailVO getRoomInfo(int serviceDetailId){
		log.info("Start ReservationServices.getRoomInfo...");
		ReserveDetailVO infoVO = new ReserveDetailVO();
		try{	
			//get reserve detail
			Map<String, Object> paramD = new HashMap<String, Object>();   
			paramD.put("serviceDetailId", serviceDetailId);
			List<ReserveDetailVO> detailList = getReserveOverviewDAO().selectReserveDetail(paramD);
			if(detailList != null && detailList.size() > 0){
				infoVO = detailList.get(0);
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return infoVO;
	}	
	@Override
	public DiscountVO checkAuthorizedDiscount(DiscountVO discountVO){
		log.info("Start ReservationServices.checkAuthorizedDiscount...");
		try{	
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("userName", discountVO.getUserName());
			paramM.put("password", discountVO.getPassword());
			UserVO userVO = getReserveOverviewDAO().selectUserByName(paramM);
			if(userVO != null && userVO.getUserId() > 0){
				discountVO.setUserId(userVO.getUserId());
				discountVO.setOrgId(userVO.getOrgId());
				getReserveOverviewDAO().checkAuthorizedDiscount(discountVO);
			}else{
				discountVO.setAuthorizedFlag("N");
			}
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return discountVO;
	}
	
	@Override
	public void deleteDetailReserveRoom(int serviceDetailId){
		log.info("Start ReservationServices.deleteDetailReserveRoom...");
		try{
			Map<String, Object> paramM = new HashMap<String, Object>();
			paramM.put("serviceDetailId", serviceDetailId);
			getReserveOverviewDAO().deleteHtServiceTrackRoomByDetailId(paramM);
			getReserveOverviewDAO().deleteHtServiceDetail(paramM);
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
	}	
	@Override
	public ItemVO getItemById(int itemId){
		log.info("Start ReservationServices.checkAuthorizedDiscount...");
		ItemVO itemVO = null;
		try{	
			String orgId = getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("orgId", orgId);
			paramM.put("itemId", itemId);
			itemVO = getReserveOverviewDAO().getItemById(paramM);
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return itemVO;
	}
	
	public List<String> checkRoomBeforeCheckin(String _arrServiceDetailId, String _arrDateFrom, String _arrDateTo, String _arrRoomId){
		log.info("Start ReservationServices.checkRoomBeforeCheckin...");
		List<String> result = new ArrayList<String>();
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId 	= user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
					
			ServiceResultMap map = null;
			if(_arrServiceDetailId != null && _arrServiceDetailId.length() > 0){
				String[] arrServiceDetailId = _arrServiceDetailId.split(",");
				String[] arrDateFrom 		= _arrDateFrom.split(",");
				String[] arrDateTo 			= _arrDateTo.split(",");
				String[] arrRoomId 			= _arrRoomId.split(",");
				int size 					= arrServiceDetailId.length;
				for(int i=0; i<size; i++){
					map = new ServiceResultMap();
					map.setUserId(StringUtils.toInt(userId));
					map.setOrgId(StringUtils.toInt(orgId));
					map.setServiceDetailId(StringUtils.toInt(arrServiceDetailId[i]));
					map.setDateFrom(DateUtils.createDate(arrDateFrom[i], false));
					map.setDateTo(DateUtils.createDate(arrDateTo[i], false));
					map.setRoomId(StringUtils.toInt(arrRoomId[i]));
					map.setReservedStatus(ReservConstants.ServiceStatusReserved);
					map.setBookedStatus(ReservConstants.ServiceStatusBooked);
					map.setCheckinStatus(ReservConstants.ServiceStatusCheckin);
					map.setCheckoutStatus(ReservConstants.ServiceStatusCheckout);
					map.setPaymentStatus(ReservConstants.ServiceStatusPayment);
					getReserveOverviewDAO().checkRoomBeforeCheckin(map);
					
					if(map.getErrFlagOut() != null && "Y".equalsIgnoreCase(map.getErrFlagOut())){
						result.add(map.getRoomNoOut());
					}
				}
			}
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return result;
	}	
	
	public String checkServiceCancelJob(int serviceHeaderId, String serviceStatus){
		log.info("Start ReservationServices.checkServiceCancelJob...");
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId 	= user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
					
			ServiceResultMap map = new ServiceResultMap();
			map.setUserId(StringUtils.toInt(userId));
			map.setOrgId(StringUtils.toInt(orgId));
			map.setServiceHeaderId(serviceHeaderId);
			map.setServiceStatus(serviceStatus);
			map.setPaymentStatus(ReservConstants.ServiceStatusPayment);
			map.setClearStatus(ReservConstants.ServiceStatusClear);
			map.setCancelStatus(ReservConstants.ServiceStatusCancel);
			getReserveOverviewDAO().checkServiceCancelJob(map);
					
			return map.getErrFlagOut();
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return null;
	}	
	
	public ReservePrintReceiptVO genAndPrintReceiptPayment(ReservePrintReceiptVO vo){
		log.info("Start ReservationServices.genAndPrintReceiptPayment...");
		ReservePrintReceiptVO resultVO = null;
		try{
			GlobalUser user = (GlobalUser)getSession().get(AppsindyConstants.S_USER_LOGIN);
			String userId 	= user!=null?String.valueOf(user.getUserId()):USERLOGIN_DEFAULT;
			String orgId 	= getSession().get(S_ORG_ID)==null?ORG_ID_DEFAULT:(String)getSession().get(S_ORG_ID);
			String custName	= "";
			String address	= "";
			if(!StringUtils.isEmpty(vo.getNewCustomerName()) && !StringUtils.isEmpty(vo.getNewAddress())){
				custName 	= vo.getNewCustomerName();
				address 	= vo.getNewAddress();
			}else{
				custName 	= vo.getCustomerName();
				address 	= vo.getAddress();
			}					
			Map<String, Object> paramM = new HashMap<String, Object>();   
			paramM.put("userId", userId);
			paramM.put("orgId", orgId);
			paramM.put("paymentId", vo.getServicePaymentId());
			paramM.put("printDate", new Date());
			paramM.put("custName", custName);
			paramM.put("address", address);			
			getReserveOverviewDAO().generatePrintReceipt(paramM);
			
			List<ReservePrintReceiptVO> result = getReserveOverviewDAO().selectPrintReceipt(paramM);
			if(result != null && result.size() > 0){
				resultVO = result.get(0);
				List<ReserveItem> itemDetail = getReserveOverviewDAO().selectPrintReceiptDetail(paramM);
				resultVO.setItemDetail(itemDetail);
			}
			List<ReservePaymentDetailVO> paymentDetailList = getReserveOverviewDAO().selectReservePaymentDetail(paramM);
			if(paymentDetailList != null && paymentDetailList.size() > 0){
				String remark = "";
				for(ReservePaymentDetailVO payVO : paymentDetailList){
					if("".equals(remark)) remark += payVO.getPaymentMethodName();
					else 				  remark += ", " + payVO.getPaymentMethodName();
				}
				resultVO.setRemark(remark);
			}
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return resultVO;
	}		
}
